package cn.rkylin.oms.base.channel.dao;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import cn.rkylin.core.IDataBaseFactory;
import cn.rkylin.oms.base.channel.domain.Channel;
import cn.rkylin.oms.base.channel.vo.ChannelVO;

/**
 * 渠道DAO
 */
@Repository(value = "channelDAO")
public class ChannelDAOImpl implements IChannelDAO {

	@Autowired
	protected IDataBaseFactory dao;
	private Map id;
	
    /**
	 * 添加渠道
	 * 
	 * @param stockIn
	 *            渠道bean
	 * @return 添加条数
	 * @throws Exception
	 *             异常
	 */
	public int insertChannel(Channel channel) throws Exception {
		return dao.insert("insertChannel", channel);
	}

	/**
	 * 修改渠道
	 *
	 * @param channel
	 *            渠道bean
	 * @return 更新条数
	 * @throws Exception
	 *             异常
	 */
	public int updateChannel(Channel channel) throws Exception {
		return dao.update("updateByChannelIdSelectiveChannel", channel);
	}
	
    /**
     * 删除渠道
     * @param channel
     *           渠道bean
     * @return 
     * @return 删除条数
     * @throws Exceptiion
     *            异常
     */
	public int deleteChannel(String channelId) throws Exception {
		return dao.delete("deleteChannel", channelId);
	}
	
	/**
	 * 查询
	 * 
	 * @param ChannelVO
     *           渠道bean
     * @return 
     * @throws Exceptiion
     *            异常
	 */
	public ChannelVO selectByChannelCode(ChannelVO channelVO) throws Exception{
		
		return (ChannelVO) dao.findOne("selectByChannelCode",channelVO);
	
	/**
	 * 查询
	 * 
	 * @param mdmCode
     *           渠道bean
     * @return 
     * @throws Exceptiion
     *            异常
	 */ 	
	 
	}
	public ChannelVO selectByChannelMdmCode(String mdmCode) throws Exception {
        return (ChannelVO) dao.findOne("selectByChannelMdmCode", mdmCode);
    }
	
	/**
	 * 获取渠道信息
	 * 
	 * @param id
     *           渠道bean
     * @return 
     * @throws Exceptiion
     *            异常
	 */ 	
	public ChannelVO findById(String id) throws Exception {
		List<ChannelVO> resultList =dao.findList("selectByPrimaryKeyChannelId", id);
        if (resultList != null && resultList.size() > 0) {
            return resultList.get(0);
        }
        return null;
	}
	
	 public int updateByMdmCodeSelectiveChannel(ChannelVO channelVO) throws Exception {
	        return dao.update("updateByMdmCodeSelectiveChannel", channelVO);
	    }
	 
	 public int insertSelectiveChannel(ChannelVO channelVO) throws Exception {
	        return dao.insert("insertSelectiveChannel", channelVO);
	    }
	
}
